# -*-coding:utf-8 -*-

from django.db import models

# Create your models here.
class Account(models.Model):
    income = models.DecimalField(max_digits=10, decimal_places=2, default=0, verbose_name='收入')
    outcome = models.DecimalField(max_digits=10, decimal_places=2, default=0)
    balance = models.DecimalField(max_digits=10, decimal_places=2, default=0)
    class Meta:
        abstract = True
    
class Member(Account):
    nickname = models.CharField(max_length=20, unique=True, verbose_name='成员姓名', help_text='请输入成员姓名')
    
    def __unicode__(self):
        return '%s' % self.nickname
    
class Team(Account):
    name = models.CharField(max_length=20)
    members = models.ManyToManyField('Member')
    
    def __unicode__(self):
        return 'Name:%s. Balance:%s(Income:+%s, Outcome:-%s)\n' \
            % (self.name, self.balance, self.income, self.outcome) + \
            'Members: %s' % ' ,'.join([str(member) for member in self.members.all()])

class Charging(models.Model):
    money = models.DecimalField(max_digits=5, decimal_places=2)
    member = models.ForeignKey('Member')
    timestamp = models.DateTimeField(auto_now_add = True)
    
    def __unicode__(self):
        return '%s charge $%s' % (self.member, self.money)
    
class Activity(models.Model):
    timestamp = models.DateTimeField()
    place = models.CharField(max_length=100)
    content = models.CharField(max_length=100)
    money = models.DecimalField(max_digits=5, decimal_places=2)
    team = models.ForeignKey('Team')
    members = models.ManyToManyField('Member')
    
    def __unicode__(self):
        return 'Time:%s. \nPlace:%s. \nContent:%s. \n' % (self.timestamp, self.place, self.content)